package ast;

import java.util.LinkedList;

import mem.interfaces.IMem;
import environnement.interfaces.IEnv;
import ast.interfaces.IAST;
import ast.interfaces.IASTfun;
import ast.interfaces.IASTif;
import ast.interfaces.IASTmove;
import ast.interfaces.IASTprog;
import ast.interfaces.IASTset;
import ast.interfaces.IASTturn;
import ast.interfaces.IASTvar;
import ast.interfaces.IASTwhile;

public class ASTprog implements IASTprog{

	private LinkedList<IAST> e;
	
	public ASTprog(LinkedList<IAST> e) {
		super();
		this.e = e;
	}
	
	@Override
	public Object eval(IAST ast,IEnv env, IMem mem){
		for(IAST cmd : e){
			if(cmd instanceof ASTmove){
				IASTmove a = ((ASTmove) cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTturn){
				IASTturn a = ((ASTturn) cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTvar){
				IASTvar a = ((ASTvar)cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTset){
				IASTset a = ((ASTset)cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTif){
				IASTif a = ((ASTif)cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTwhile){
				IASTwhile a = ((ASTwhile)cmd);
				a.eval(a,env, mem);
			}
			if(cmd instanceof ASTfun){
				IASTfun a = ((ASTfun)cmd);
				a.eval(a,env, mem);
			}
		}
		
		return null;
	}

	@Override
	public String toTreeString(String ident,IEnv env,IMem mem) {
		String ret="";
		for(IAST cmds : e){
			ret += ident + cmds.toTreeString(ident + "",env,mem) + ";";
		}
		return "[" + ret + "]";
	}
	
}
